package com.cskaoyan.controller.admin.mallcontroller;

import com.cskaoyan.bo.mallbo.BrandCreateBo;
import com.cskaoyan.bo.mallbo.BrandUpdateBo;
import com.cskaoyan.service.mallservice.BrandService;
import com.cskaoyan.vo.BaseRespVo;
import com.cskaoyan.vo.mallvo.BrandCreateVo;
import com.cskaoyan.vo.mallvo.BrandUpdateVo;
import com.cskaoyan.vo.mallvo.BrandVo;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author hsp
 * @date 2021/5/9 16:41
 */
@RestController
@RequestMapping("admin/brand")
public class BrandController {
    @Autowired
    BrandService brandService;



    @RequiresPermissions(value = {"admin:brand:list"},logical = Logical.OR)
    @RequestMapping("list")//admin/brand/list?page=1&limit=20&sort=add_time&order=desc
    public BaseRespVo list(Integer page,Integer limit,Integer id,String name,String sort,String order)
    {
        BrandVo brandVo =  brandService.queryBrand(page,limit,id,name,sort,order);

        return BaseRespVo.ok(brandVo);

    }

    /**
     * {"name":"华为",
     * "desc":"pad",
     * "floorPrice":"3999",
     * "picUrl":"http://localhost:8083/wx/storage/fetch/37616137336338342d63.jpg"}
     * @return
     */
    @RequiresPermissions("admin:brand:create")
    @RequestMapping("create")
    public BaseRespVo create(@RequestBody BrandCreateBo brandCreateBo){

       BrandCreateVo brandCreateVo =  brandService.createBrand(brandCreateBo);

       return  BaseRespVo.ok(brandCreateVo);
    }

    @RequiresPermissions("admin:brand:update")
    @RequestMapping("update")
    public BaseRespVo update(@RequestBody BrandUpdateBo brandUpdateBo){


        BrandUpdateVo brandUpdateVo =  brandService.updateBrand(brandUpdateBo);

      return BaseRespVo.ok(brandUpdateVo);
    }

    @RequiresPermissions("admin:brand:delete")
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody BrandUpdateBo brandUpdateBo){

        brandService.deleteBrandById(brandUpdateBo.getId());

        return BaseRespVo.ok();
    }
}
